//


#import "AM_HomeDetailView.h"

//
@interface AM_HomeDetailView ()
/** <#Description#>*/
@property (nonatomic, strong) UILabel *nameLabel;
/** <#Description#>*/
@property (nonatomic, strong) UILabel *accountLabel;
/** <#Description#>*/
@property (nonatomic, strong) UILabel *passwordLabel;
/** <#Description#>*/
@property (nonatomic, strong) UIImageView *img;

@end

@implementation AM_HomeDetailView

- (instancetype)initWithFrame:(CGRect)frame {
    if ([super initWithFrame:frame]) {
        //
        UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(kRelativeWidth(12), kRelativeHeight(10), kMainScreenWidth-kRelativeWidth(24), kRelativeHeight(20))];
        nameLabel.textColor = RGB(60, 60, 60);
        nameLabel.font = FontPFRegular(kRelativeWidth(16));
        [self addSubview:nameLabel];
        self.nameLabel = nameLabel;
        //
        UILabel *accountLabel = [[UILabel alloc]initWithFrame:CGRectMake(kRelativeWidth(12), CGRectGetMaxY(nameLabel.frame)+kRelativeHeight(20), kMainScreenWidth - kRelativeWidth(24), kRelativeHeight(20))];
        accountLabel.textColor = RGB(60, 60, 60);
        accountLabel.font = FontPFRegular(kRelativeWidth(16));
        [self addSubview:accountLabel];
        self.accountLabel = accountLabel;
        //
        UILabel *passwordLabel = [[UILabel alloc]initWithFrame:CGRectMake(kRelativeWidth(12), CGRectGetMaxY(accountLabel.frame)+kRelativeHeight(20), kMainScreenWidth - kRelativeWidth(24), kRelativeHeight(20))];
        passwordLabel.textColor = RGB(60, 60, 60);
        passwordLabel.font = FontPFRegular(kRelativeWidth(16));
        [self addSubview:passwordLabel];
        self.passwordLabel = passwordLabel;
        //
        UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(kRelativeWidth(12), CGRectGetMaxY(passwordLabel.frame)+kRelativeHeight(20), kRelativeWidth(50), kRelativeHeight(50))];
        [self addSubview:img];
        self.img = img;
        //
        UIButton *deleteButton = [[UIButton alloc]initWithFrame:CGRectMake(kRelativeWidth(48), kMainScreenHeight- UI_NAV_BAR_HEIGHT - kRelativeHeight(100), kMainScreenWidth - kRelativeWidth(96), kRelativeHeight(40))];
        [deleteButton setTitle:@"Delect" forState:UIControlStateNormal];
        [deleteButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [deleteButton setBackgroundColor:RGB(222, 152, 84)];
        [deleteButton.titleLabel setFont:FontPFRegular(kRelativeWidth(16))];
        [deleteButton addTarget:self action:@selector(action) forControlEvents:UIControlEventTouchUpInside];
        [deleteButton am_rounded:10];
        [self addSubview:deleteButton];
        
        
        
    }return self;
}
//删除
- (void)action {
    //
    if ([self.delegate respondsToSelector:@selector(setDeleteData:)]) {
        [self.delegate setDeleteData:self];
    }
}


//
- (void)setModel:(HomeData *)model {
    _model = model;
    //
    self.nameLabel.text = [NSString stringWithFormat:@"Name：%@",model.name];
    self.accountLabel.text = [NSString stringWithFormat:@"Account：%@",model.account];
    self.passwordLabel.text = [NSString stringWithFormat:@"Password：%@",model.password];
    
    //
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    // 读取沙盒路径图片
    NSString *imageFilePath = [path stringByAppendingPathComponent:model.img ];
    UIImage *imgFromUrl=[[UIImage alloc]initWithContentsOfFile:imageFilePath];
    self.img.image = imgFromUrl;
    
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
